package lib;

import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-08-08
 * Time: 22:40
 */
public class JDBC {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("lmh041105666");

        Connection connection = (Connection) dataSource.getConnection();

        PreparedStatement statement = connection.prepareStatement("select * from goods");

        ResultSet resultSet = statement.executeQuery();
        while(resultSet.next()) {
            String name = resultSet.getString("name");
            int inventory = resultSet.getInt("inventory");

            System.out.println(name + inventory);
        }
        statement.close();
        connection.close();

    }
}
